<template>
  <div class="apply">
    <div class="balance_title t_center">
      <img class="balance_title_bg" src="../../assets/img/balance_bg.png" height="300" width="710"/>
      <div class="infos">
        <div class="font_size24 color_ff">我的余额</div>
        <div class="font_size48 color_ff m_t20">￥{{money}}</div>
      </div>
    </div>
    <div class="apply_info bg_colorff">
      <div class="font_size28 color_33">提现金额</div>
      <div><input class="input_money border_b m_t20 m_b20 line90" type="number" v-model="tixianmoney" placeholder="输入提现金额"/></div>
      <div class="font_size20 color_99 m_b20"><span>提现手续：￥{{cashcharge}}</span>   <span class="m_l20">最小提现金额：￥{{cashmoney}}</span></div>
      <div class="flex line90 font_size32 color_33 border_b m_t20">
        <div>提现到</div>
        <div class="flex-1 t_right" @click="shoubanklistFn"><span v-if="!bandinfo.id">添加银行卡</span><span v-if="bandinfo.id">{{bandinfo.nameinfo}}</span><img class="left_icon" src="../../assets/img/icon/jiantou_left.png"/></div>
      </div>
      <div v-if="regionVisible">
        <!--<choose-bank></choose-bank>-->
        <!--<bank-list></bank-list>-->
      </div>

      <div class="btn font_size28" @click="applyFn">申请提现</div>

    </div>


  </div>
</template>

<script>
  import BankList from '../../components/public/BankcardList';
  // import ChooseBank from '../bankcord/choosebank';
    export default {
      name: "apply",
      data(){
          return{
            money: '',
            tixianmoney: '',
            bank_cord: '',
            cashcharge: '',
            cashmoney: '',
            regionVisible: false,
          }
      },
      components: {
        BankList,
        // ChooseBank
      },
      computed:{
        band_id(){
          return this.$store.state.bank_id
        },
        band_name(){
          return this.$store.state.bank_name
        },
        bandinfo(){
          return this.$store.state.choosebankinfo
        },
      },
      beforeRouteLeave(to, from, next) {
        // 设置下一个路由的 meta
        if(to.fullPath == '/balance'){
          this.$store.commit('setbankname', '')
          this.$store.commit('setbankid', '')
        }
        next();
      },

      created(){
        this.money = this.$store.state.balancemoney
        this.getinfosFn()
      },
      methods:{
        getinfosFn(){
         this.$util.get('user/withdrawInfo', {
           uid: this.$store.state.userinfo.uid
         }).then(data => {
           this.money = data.data.balance
           this.cashcharge = data.data.cash_charge
           this.cashmoney = data.data.cash_money
         })
        },
        shoubanklistFn(){
          this.$router.push('/choosecard')
          // this.regionVisible = !this.regionVisible
        },
        applyFn(){
          var self = this
          if(!self.tixianmoney){
            this.$toast('请输入提现金额')
            return
          }
          if(!self.tixianmoney>self.money){
            this.$toast('余额不足，请重新输入提现金额')
            return
          }
          if(!self.bandinfo.id){
            this.$toast('请选择提现银行卡')
            return
          }

          self.$util.post('user/withdraw', {
            uid: self.$store.state.userinfo.uid,
            apply_balance: self.tixianmoney,
            balance: self.tixianmoney-self.cashcharge,
            bank_id: self.bandinfo.id
          }).then(data => {
            if(data.status == 1){
              self.$toast('申请提现成功')
            }else{
              self.$toast(data.message)
            }
          })
        },
      }
    }
</script>

<style lang="less" scoped>
  @import "../../assets/css/balance/apply";
</style>
